package com.kuanter.kuanterauto.adapter;

import java.util.List;

import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kuanter.kuanterauto.R;
import com.kuanter.kuanterauto.entity.KuanterService.Service;

public class PopServiceAdapter extends BaseAdapter {
	LayoutInflater factory;
	List<Service> list;
	private int service_selected = -1;
	
	public PopServiceAdapter(LayoutInflater factory,List<Service> list) {
		this.factory = factory;
		this.list = list;
	}

	@Override
	public int getCount() {
		int size = 0;
		if(list != null) {
			size = list.size();
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}
 
	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null) {
			convertView = factory.inflate(R.layout.list_service_item, null);
		}
		
		TextView sort_type = (TextView) convertView.findViewById(R.id.sort_type);
		sort_type.setText(list.get(position).getServiceName());
		
		Log.i("bbb", service_selected + "------------------------");
		if(position == service_selected) {
			convertView.setBackgroundColor(Color.parseColor("#008CF0"));
			sort_type.setTextColor(Color.WHITE);
		} else {
			convertView.setBackgroundResource(R.drawable.list_site_selector);  //pop_condicition_service
//			convertView.setBackgroundDrawable(null);
			sort_type.setTextColor(Color.parseColor("#c8c8c8"));
		}
		return convertView;
	}

	public List<Service> getList() {
		return list;
	}

	public void setList(List<Service> list) {
		this.list = list;
	}

	public int getService_selected() {
		return service_selected;
	}

	public void setService_selected(int service_selected) {
		this.service_selected = service_selected;
	}
	
}
